<?php
namespace app\common\model;
use think\Model;
use think\model\concern\SoftDelete;

class Goods extends Model
{
    use SoftDelete;
    protected $deleteTime = 'delete_time';
    protected $defaultSoftDelete = 0;
    protected $autoWriteTimestamp = true;
    
    protected function base($query)
    {

    }
    //商品分类
    protected function cate()
    {
        return self::belongsTo(GoodCate::class, 'cate_id')->bind(['cate_name'=>'name']);
    }
    //商品标签
    protected function tag()
    {
        return self::belongsTo(GoodTag::class, 'tag_id')->bind(['tag_name'=>'name']);
    }
    //获取商品简介
    public static function getGoodsSummary()
    {
        return self::field('goods_name as name,goods_price as price,market_price,img,id as hash_id')->where('status',1)->order('sort','ASC')->select()->toArray();
    }

    protected function getHashIdAttr($value)
    {
        return md6($value);
    }
    
    //通过ID获取商品
    public static function getGoodById($value)
    {
        $data = self::find($value);
        $list = GoodSku::getSku($data['id']);
        $data['sku'] = $list;
        return $data;

    }

}